package com.xmb.wechat.delegate;

import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xmb.wechat.R;
import com.xmb.wechat.baserecyclerview.BaseRecyclerViewManager;
import com.xmb.wechat.bean.WechatContactBean;
import com.xmb.wechat.definterface.GroupTalkListener;
import com.xmb.wechat.dialog.RoleEditDialog;

import java.util.ArrayList;

/**
 * @Author lijiangop
 * @CreateTime 2020/4/30 16:11
 */
public class GroupTalkAddDelegate extends BaseRecyclerViewManager {

    private GroupTalkListener listener;
    private Activity          activity;
    private RoleEditDialog    mRoleEditDialog;

    public GroupTalkAddDelegate(Activity activity, GroupTalkListener listener) {
        super(activity);
        this.activity = activity;
        this.listener = listener;
    }

    @Override
    public BaseQuickAdapter initAdapter() {
        return new BaseQuickAdapter<WechatContactBean, BaseViewHolder>(R.layout.item_group_talk_add, new ArrayList<>()) {
            @Override
            protected void convert(BaseViewHolder helper, WechatContactBean item) {
                ImageView imageView = helper.getView(R.id.iv_avatar);
                WechatContactBean.setupAvatarIntoImageView(item.getAvatarSrc(), "", item.getAvatar(), imageView, 12);
                helper.setText(R.id.tv_avatar, TextUtils.isEmpty(item.getName()) ? "" : item.getName());
                helper.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (listener != null)
                            listener.onClick(mData.indexOf(item), item);
                    }
                });
                helper.itemView.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View view, MotionEvent motionEvent) {
                        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                            if (listener != null)
                                listener.onItemDrag(helper);
                        }
                        return false;
                    }
                });
            }
        };
    }

    @Override
    protected RecyclerView.LayoutManager getLayoutManager() {
        return new GridLayoutManager(context, 4);
    }
}
